package com.shop2cn.app.liveseller.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.app.liveseller.parameter.CreateSellerLiveBean;
import com.shop2cn.app.liveseller.parameter.LiveRoomDto;
import com.shop2cn.app.liveseller.parameter.QueryInheritLiveListBean;
import com.shop2cn.app.liveseller.service.QueryInheritLiveListCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.LiveRoom;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
/**
*获取代理上级联播列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryInheritLiveList{
	private static QueryInheritLiveListBean queryinheritlivelistBean;
	private static QueryInheritLiveListCall queryinheritlivelistCall;
	private static LiveRoomShop2cnWapper LiveRoomShop2cnWapper;
	private static int sellerId ;
	private static String token ;
	private static int csId;
	private static String cstoken;
	private static int mchId_Agent;
	@BeforeClass
	public static void setUp() throws Exception {
		Logger.createResultFile("获取代理上级联播列表");

		sellerId = GodmchManageCallService.CreateSellerMch();
		token=AuthCallServiceV2.createToken(sellerId, "app");
		csId = GodmchManageCallService.bindClientService(
				sellerId, 1);
		cstoken = AuthCallServiceV2.createToken(csId, "app");
		 mchId_Agent=GodmchManageCallService.createAgent(sellerId);
	}

	@Before
	public void caseUp() throws Exception {
		queryinheritlivelistBean=new QueryInheritLiveListBean();
		queryinheritlivelistCall=new QueryInheritLiveListCall();
		LiveRoomShop2cnWapper=new LiveRoomShop2cnWapper();
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryinheritlivelistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryInheritLiveList_001() {
		Logger.start(true,"获取代理上级联播列表成功");
		try {
			 CreateSellerLiveBean c = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			 c.getLiveDto().setLiveInherit(true);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(c,sellerId);
			LiveRoomShop2cnCallService.AddLiveToShop(createlive.getId(),mchId_Agent , sellerId);
			queryinheritlivelistBean.setPageIndex(1);
			queryinheritlivelistBean.setPageSize(10);
			queryinheritlivelistBean.setShopId(mchId_Agent);
			String head="accesstoken="+token;
			queryinheritlivelistCall.addHeader("ymt-pars", head);
			queryinheritlivelistCall.setData(queryinheritlivelistBean);
			queryinheritlivelistCall.callService();
			Logger.verifyEquals("1", queryinheritlivelistCall.getString("totals"), "验证条数");
			List<LiveRoomDto> lives = queryinheritlivelistCall.getLiveRoomDtos();
			Logger.debug(FormatUtil.beanToGSONString( lives));
			//liveInherit是否允许联播    inherited 是否已经联播
			Logger.verifyEquals(true, lives.get(0).getInherited(), "是否已经联播");
			Logger.verifyEquals(true, lives.get(0).getLiveInherit(), "是否允许联播");
			//如果直播是继承的，那就是继承直播的商户的id    如果直播是自己创建  那就是自己的id
			Logger.verifyEquals(sellerId, lives.get(0).getChildShopId(), "继承直播的商户的id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryInheritLiveList_002() {
		Logger.start(true,"直播未添加Inherited为false");
		try {
			 CreateSellerLiveBean c = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			 c.getLiveDto().setLiveInherit(true);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(c,sellerId);
//			LiveRoomShop2cnCallService.AddLiveToShop(createlive.getId(),mchId_Agent , sellerId);
			queryinheritlivelistBean.setPageIndex(1);
			queryinheritlivelistBean.setPageSize(10);
			queryinheritlivelistBean.setShopId(mchId_Agent);
			String head="accesstoken="+token;
			queryinheritlivelistCall.addHeader("ymt-pars", head);
			queryinheritlivelistCall.setData(queryinheritlivelistBean);
			queryinheritlivelistCall.callService();
			Logger.verifyEquals("1", queryinheritlivelistCall.getString("totals"), "验证条数");
			List<LiveRoomDto> lives = queryinheritlivelistCall.getLiveRoomDtos();
			Logger.debug(FormatUtil.beanToGSONString( lives));
			//liveInherit是否允许联播    inherited 是否已经联播
			Logger.verifyEquals(false, lives.get(0).getInherited(), "是否已经联播");
			Logger.verifyEquals(true, lives.get(0).getLiveInherit(), "是否允许联播");
			//如果直播是继承的，那就是继承直播的商户的id    如果直播是自己创建  那就是自己的id
			Logger.verifyEquals(sellerId, lives.get(0).getChildShopId(), "继承直播的商户的id");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryInheritLiveList_003() {
		Logger.start(true,"查询自己创建的直播失败");
		try {
			//不会查出自己的直播
			CreateSellerLiveBean c = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			 c.getLiveDto().setLiveInherit(true);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(c,mchId_Agent);
//			LiveRoomShop2cnCallService.AddLiveToShop(createlive.getId(),mchId_Agent , sellerId);
			queryinheritlivelistBean.setPageIndex(1);
			queryinheritlivelistBean.setPageSize(10);
			queryinheritlivelistBean.setShopId(mchId_Agent);
			String head="accesstoken="+token;
			queryinheritlivelistCall.addHeader("ymt-pars", head);
			queryinheritlivelistCall.setData(queryinheritlivelistBean);
			queryinheritlivelistCall.callService();
			Logger.verifyEquals("0", queryinheritlivelistCall.getString("totals"), "验证条数");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryInheritLiveList_004() {
		Logger.start(true,"上级直播不可继承-返回空");
		try {
			 CreateSellerLiveBean c = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			 c.getLiveDto().setLiveInherit(false);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(c,sellerId);
//			LiveRoomShop2cnCallService.AddLiveToShop(createlive.getId(),mchId_Agent , sellerId);
			queryinheritlivelistBean.setPageIndex(1);
			queryinheritlivelistBean.setPageSize(10);
			queryinheritlivelistBean.setShopId(mchId_Agent);
			String head="accesstoken="+token;
			queryinheritlivelistCall.addHeader("ymt-pars", head);
			queryinheritlivelistCall.setData(queryinheritlivelistBean);
			queryinheritlivelistCall.callService();
			Logger.verifyEquals("0", queryinheritlivelistCall.getString("totals"), "验证条数");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}